package com.bupt.controller.common;

import com.bupt.annotation.AccessLimit;
import com.bupt.constants.ResponseResult;
import com.bupt.dto.sys.LoginUserDto;
import com.bupt.dto.sys.UserDto;
import com.bupt.service.common.WordAndExcelExportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequestMapping("/api")
@Api(tags = {"项目中excel的操作"})
public class ExcelController {

    @Resource
    private WordAndExcelExportService wordAndExcelExportService;


    @ApiOperation("下载节点模板")
    @AccessLimit(interfaceName = "downloadNodeMould", isEnableClickLimit = false)
    @GetMapping("/downloadNodeMould")
    public Object downloadNodeMould(HttpServletRequest request,
                                    HttpServletResponse response) {
        try {
            Object o = wordAndExcelExportService.downLoadNodeMould(request,response);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("下载fiber链路模板")
    @AccessLimit(interfaceName = "downLoadFiberLinkMould", isEnableClickLimit = false)
    @GetMapping("/downLoadFiberLinkMould")
    public Object downLoadFiberLinkMould(HttpServletRequest request,
                                    HttpServletResponse response) {
        try {
            Object o = wordAndExcelExportService.downLoadFiberLinkMould(request,response);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }


    @ApiOperation("下载wdm链路模板")
    @AccessLimit(interfaceName = "downLoadWdmLinkMould", isEnableClickLimit = false)
    @GetMapping("/downLoadWdmLinkMould")
    public Object downLoadWdmLinkMould(HttpServletRequest request,
                                         HttpServletResponse response) {
        try {
            Object o = wordAndExcelExportService.downLoadWdmLinkMould(request,response);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("下载sdh链路模板")
    @AccessLimit(interfaceName = "downLoadSdhLinkMould", isEnableClickLimit = false)
    @GetMapping("/downLoadSdhLinkMould")
    public Object downLoadSdhLinkMould(HttpServletRequest request,
                                       HttpServletResponse response) {
        try {
            Object o = wordAndExcelExportService.downLoadSdhLinkMould(request,response);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }


    @ApiOperation("下载otn链路模板")
    @AccessLimit(interfaceName = "downLoadOtnLinkMould", isEnableClickLimit = false)
    @GetMapping("/downLoadOtnLinkMould")
    public Object downLoadOtnLinkMould(HttpServletRequest request,
                                       HttpServletResponse response) {
        try {
            Object o = wordAndExcelExportService.downLoadOtnLinkMould(request,response);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("excel导入节点")
    @AccessLimit(interfaceName = "upLoadNodeFile", isEnableClickLimit = false)
    @PostMapping("/upLoadNodeFileToProject/{ProjectId}")
    public Object upLoadNodeFile(@ApiIgnore UserDto userDto,@ApiIgnore HttpServletRequest request,
                                 @PathVariable("ProjectId")String projectId,
                                 @RequestParam("file") MultipartFile file) {
        try {
            Object o = wordAndExcelExportService.upLoadNodeFileToProject(userDto,request,projectId, file);
            return ResponseResult.createOK(o);
        } catch (Exception e) {

            return ResponseResult.createFail(e.getMessage());
        }
    }




    @ApiOperation("excel导入fiber链路")
    @AccessLimit(interfaceName = "upLoadFiberLinkFile", isEnableClickLimit = false)
    @PostMapping("/upLoadFiberLinkFileToProject/{ProjectId}")
    public Object upLoadFiberLinkFile(UserDto userDto,
                                 @PathVariable("ProjectId")String projectId,
                                 @RequestParam("file") MultipartFile file) {
        try {
            Object o = wordAndExcelExportService.upLoadFiberLinkFileToProject(userDto,projectId,file);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }


    @ApiOperation("excel导入wdm链路")
    @AccessLimit(interfaceName = "upLoadFiberLinkFile", isEnableClickLimit = false)
    @PostMapping("/upLoadWdmLinkFileToProject/{ProjectId}")
    public Object upLoadWdmLinkFile(UserDto userDto,
                                      @PathVariable("ProjectId")String projectId,
                                      @RequestParam("file") MultipartFile file) {
        try {
            Object o = wordAndExcelExportService.upLoadWdmLinkFileToProject(userDto, file,projectId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("excel导入otn链路")
    @AccessLimit(interfaceName = "upLoadOtnLinkFile", isEnableClickLimit = false)
    @PostMapping("/upLoadOtnLinkFile/{ProjectId}")
    public Object upLoadOtnLinkFile(UserDto userDto,
                                    @PathVariable("ProjectId")String projectId,
                                    @RequestParam("file") MultipartFile file) {
        try {
            Object o = wordAndExcelExportService.upLoadOtnLinkFileToProject(userDto, file,projectId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }




    @ApiOperation("excel导入sdh链路")
    @AccessLimit(interfaceName = "upLoadSdhLinkFileToProject", isEnableClickLimit = false)
    @PostMapping("/upLoadSdhLinkFileToProject/{ProjectId}")
    public Object upLoadSdhLinkFileToProject(UserDto userDto,
                                    @PathVariable("ProjectId")String projectId,
                                    @RequestParam("file") MultipartFile file) {
        try {
            Object o = wordAndExcelExportService.upLoadSdhLinkFileToProject(userDto, file,projectId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }


    @ApiOperation("下载业务的导入模版")
    @AccessLimit(interfaceName = "下载业务的导入模版")
    @GetMapping("/downLoadDemandMould")
    public Object downLoadDemandMould(@ApiIgnore UserDto userDto,
                                           @ApiIgnore HttpServletRequest request,
                                           @ApiIgnore HttpServletResponse response) {
        try {
            Object o = wordAndExcelExportService.downLoadDemandMould(userDto, request, response);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }


    @ApiOperation("上传我们的业务的信息")
    @AccessLimit(interfaceName = "上传我们的业务的信息")
    @PostMapping("/upLoadDemandToProject/{projectId}")
    public Object upLoadDemandToProject(@ApiIgnore UserDto userDto,
                                        @PathVariable("projectId") String pId,
                                        @RequestParam("file") MultipartFile file) {
        try {
            Object o = wordAndExcelExportService.upLoadDemandToProject(userDto, pId, file);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("下载一个项目里面的所有的节点")
    @AccessLimit(interfaceName = "下载一个项目里面的所有的业务")
    @GetMapping("/downLoadNodeFromProject/{pId}")
    public Object downLoadNode(@ApiIgnore UserDto userDto,
                                       @ApiIgnore HttpServletRequest request,
                                       @ApiIgnore HttpServletResponse response,
                                       @PathVariable("pId") String pId) {
        try {
            Object o = wordAndExcelExportService.downloadNode(userDto, request, response, pId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("下载fiber的数据")
    @AccessLimit(interfaceName = "下载fiber的数据", isEnableClickLimit = false)
    @GetMapping("/downloadFiberDataFromProject/{pId}")
    public Object downloadFiberDataFromProject(@ApiIgnore UserDto userDto,
                                               HttpServletRequest request,
                                               HttpServletResponse response,
                                               @PathVariable("pId") String pId) {
        try {
            Object o = wordAndExcelExportService.downloadFiberDataFromProject(userDto, request, response, pId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("下载wdm的数据")
    @AccessLimit(interfaceName = "下载wdm的数据", isEnableClickLimit = false)
    @GetMapping("/downloadWdmDataFromProject/{pId}")
    public Object downloadWdmDataFromProject(@ApiIgnore UserDto userDto,
                                             HttpServletRequest request,
                                             HttpServletResponse response,
                                             @PathVariable("pId") String pId) {
        try {
            Object o = wordAndExcelExportService.downloadWdmDataFromProject(request, response, pId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("下载otn的数据")
    @AccessLimit(interfaceName = "下载otn的数据", isEnableClickLimit = false)
    @GetMapping("/downloadOtnDataFromProject/{pId}")
    public Object downloadOtnDataFromProject(@ApiIgnore UserDto userDto,
                                             HttpServletRequest request,
                                             HttpServletResponse response,
                                             @PathVariable("pId") String pId) {
        try {
            Object o = wordAndExcelExportService.downloadOtnDataFromProject(request, response, pId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("下载sdh的数据")
    @AccessLimit(interfaceName = "下载sdh的数据", isEnableClickLimit = false)
    @GetMapping("/downloadSdhDataFromProject/{pId}")
    public Object downloadSdhDataFromProject(@ApiIgnore UserDto userDto,
                                             HttpServletRequest request,
                                             HttpServletResponse response,
                                             @PathVariable("pId") String pId) {
        try {
            Object o = wordAndExcelExportService.downloadSdhDataFromProject(request, response, pId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }


    @ApiOperation("下载一个项目里面的所有的业务")
    @AccessLimit(interfaceName = "下载一个项目里面的所有的业务")
    @GetMapping("/downLoadNeedServices/{pId}")
    public Object downLoadNeedServices(@ApiIgnore UserDto userDto,
                                       @ApiIgnore HttpServletRequest request,
                                       @ApiIgnore HttpServletResponse response,
                                       @PathVariable("pId") String pId) {
        try {
            Object o = wordAndExcelExportService.downLoadNeedServices(userDto, request, response, pId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }


    @ApiOperation("下载规划结果")
    @AccessLimit(interfaceName = "下载规划结果")
    @GetMapping("/downloadPlanResult/{pId}")
    public Object downloadPlanResult(@ApiIgnore UserDto userDto,
                                     @ApiIgnore HttpServletRequest request,
                                     @ApiIgnore HttpServletResponse response,
                                     @PathVariable("pId") String pId) {
        try {
            Object o = wordAndExcelExportService.downLoadPlanResult(userDto, request, response, pId);
            return ResponseResult.createOK(o);
        } catch (Exception e) {
            return ResponseResult.createFail(e.getMessage());
        }
    }

}
